//
//  AssetTableViewCell.swift
//  Exchange
//
//  Created by 孟祥群 on 2018/5/4.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit

class AssetTableViewCell: BaseTableViewCell {
    var canUseLabel:UILabel?
    var noUseLabel:UILabel?
    lazy var titleLabel:UILabel = {
       let label = BaseLabel(style: .oneStyle)
       return label
    }()
    
    override func setUpUI() {
        super.setUpUI()
        titleLabel.font = UIFont.systemFont(ofSize: 12)
        self.contentView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(42)
            make.top.equalToSuperview().offset(18)
        }
        
        self.contentView.addSubview(self.iconImage)
        self.iconImage.layer.cornerRadius = 10
        self.iconImage.layer.masksToBounds = true
        self.iconImage.snp.makeConstraints { (make) in
            make.centerY.equalTo(titleLabel)
            make.left.equalToSuperview().offset(15)
            make.width.height.equalTo(20)
        }
        
        for i in 0..<2 {
            let moneyLabel = BaseLabel(style: .oneStyle)
            moneyLabel.font = UIFont.systemFont(ofSize: 14)
            if i == 0 {
                canUseLabel = moneyLabel
            }else {
                noUseLabel = moneyLabel
            }
            self.contentView.addSubview(moneyLabel)
            moneyLabel.snp.makeConstraints { (make) in
                make.left.equalToSuperview().offset(kSCREEN_WIDTH/3*(i==0 ? 1 : 2))
                make.width.lessThanOrEqualTo(kSCREEN_WIDTH/3-5)
                make.top.equalToSuperview().offset(20)
            }
            
            let kindLabel = BaseLabel(style: .twiceStyle)
            kindLabel.font = UIFont.systemFont(ofSize: 12)
            kindLabel.text = i == 0 ? kText("可用") : kText("冻结")
            self.contentView.addSubview(kindLabel)
            kindLabel.snp.makeConstraints { (make) in
                make.left.equalToSuperview().offset(kSCREEN_WIDTH/3*(i==0 ? 1 : 2))
                make.top.equalTo(moneyLabel.snp.bottom).offset(10)
            }
        }
    }
    
    override func setModel(model: BaseModel) {
        let newModel = model as? AssetModel
        canUseLabel?.text = CYCalculate.cy_intercept(number: (newModel?.currentAmount)!, digit: (newModel?.coinPrecision)!,isCover: true)
        noUseLabel?.text =  CYCalculate.cy_intercept(number: (newModel?.frozenAmount)!, digit: (newModel?.coinPrecision)!,isCover: true)
        titleLabel.text = newModel?.coinCode.count != 0 ?  newModel?.coinCode : ""
        self.iconImage.sd_setImage(with: URL(string: (newModel?.logoUrl)!), placeholderImage:UIImage(named: "coinIcon") )
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
